<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
 	<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <div class="ibox-title" style="border-color: white;">
                    <div class="row">
                        <div class="col-sm-3" style="width: 100%;">
                            <div class="input-group" style="width: 100%;">
                                <input id="name" type="text" placeholder="请输入名称" class="input-sm form-control" style="width: 15%;">
                                <input type="hidden"  id="taskId" value="${task.id }"/>
                                <input type="hidden"  id="status" value="${task.status }"/>
                                <span class="input-group-btn"  style="float: left;">
                                        <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a> </span>
                             </div>
                        </div>
                    </div>
                </div>
                <!-- biaogebigin -->
                <div class="ibox-content" style=" padding-left: 0px; margin-top: 10px;">
                    <div class="jqGrid_wrapper">
                        <table id="table_list"></table>
                        <div id="pager_list"></div>
                    </div>
                </div>
                <!-- tableover -->
            </div>
            <!-- PAGE CONTENT ENDS HERE -->

        </div>
        <!--/row-->
    </div>
    <!--/#page-content-->
</div>
<!--/.fluid-container#main-container-->
<script type="text/javascript">
    $(top.hangge());
    var taskId = $("#taskId").val();
    var pStatus = $("#status").val();
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#table_list").jqGrid({
            url: '<%=contextPath%>/taskSubManager/listData',
            datatype: "json",
            postData: {'taskId':taskId}, //发送数据
            autowidth: true,
            rownumbers: true,
            shrinkToFit: true,
            sortname: 'startDate',
            sortorder: "desc",
            mtype: "post",
            rowNum: 10,
            rowList: [10, 20, 30],
            colNames: [
			"id",
			"任务类别",
			"执行人",
			"任务标题",
			"开始时间",
			"结束时间",
			"紧急程度",
			"目标数量",
			"任务状态",
	         "操作"],
            colModel: [
			{name: "id",index: "id",hidden: true}, 
			{name:"typeName",index:"typeName",width:100},
			{name:"createUser.truename",index:"createUser.truename",width:100},
			{name:"title",index:"title",width:100},
			{name:"startDate",index:"startDate",width:100},
			{name:"endDate",index:"endDate",width:100},
			{name:"dictDegree",index:"dictDegree",width:100},
			{name:"targetQuantity",index:"targetQuantity",width:100},
			{name:"dictStatus",index:"dictStatus",width:100,
				formatter: function (value, options, row) {
					return '<a href="#" onclick="openStatus(&quot;'+row.id+'&quot;)" class="btn btn-sm btn-warning" title="查看详情">'+value+'</a>';
				}
			},
	        {
                formatter: function (cellvalue, options, row) {
                	var htm="";
                	if(row.status<2 || row.status==4){
                		htm +=" <s:hasPermission name="taskSubManager:edit"><a class='btn btn-sm btn-primary' title='是否完成' onclick='showtasks(&quot;" + row.id + "&quot;)'><i class='icon-check'></i></a></s:hasPermission> "; 
                	}
                	if(row.status==2){
                		htm +=" <s:hasPermission name="taskSubManager:edit"><a class='btn btn-sm btn-warning' title='检查是否完成' onclick='checktasks(&quot;" + row.id + "&quot;)'><i class='icon-ok'></i></a></s:hasPermission> "; 
                	}
                    return htm+"<s:hasPermission name="taskSubManager:detail"><a class='btn btn-sm btn-info' title='查看' onclick='showeye(&quot;" + row.id + "&quot;)'><i class='icon-eye-open'></i></a></s:hasPermission> " 
                     +" <s:hasPermission name="taskSubManager:delete"><a class='btn btn-sm btn-danger' title='删除' onclick='del(&quot;" + row.id + "&quot;)'><i class='icon-trash'></i></a></s:hasPermission> ";
                },
                width: 180
            }],
            height: $(window).height() - 170,
            pager: "#pager_list",
            //multiselect: true,//多选按钮
            //multiboxonly: true,
            viewrecords: true,
            hidegrid: false
        });
        //表格自适应高宽
        $(window).bind("resize", function () {
            var b = $(".jqGrid_wrapper").width();
            $("#table_list").setGridWidth(b);
            $("#table_list").setGridHeight($(window).height() - 170);
        })
        $("#table_list").navGrid('#pager_list', {edit: false, add: false, del: false, search: false})
        /* 判断是否有添加权限 */
        //检索
        $("#find_btn").click(function () {
            var name = $("#name").val();
            $("#table_list").jqGrid('setGridParam', {
                postData: {'name': name}, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });
        
    //查看
    function showeye(id) {
        openyem("查看任务子表", "<%=contextPath%>/taskSubManager/detailView?id=" + id, 550, 500);
    }
    //删除
    function del(id) {
        swalopen(id, "<%=contextPath%>/taskSubManager/delete");
    };
    //修改
    function showedit(id) {
        openyem("修改任务子表", "<%=contextPath%>/taskSubManager/editView?id=" + id, 550, 500);
    }
    //添加
    function showadd(id) {
        openyem("添加任务子表", "<%=contextPath%>/taskSubManager/addView", 550, 500);
    }
    function updateStatus(id) {
    	openyem("修改状态", "<%=contextPath%>/taskSubManager/statusView?id=" + id, 500, 350);
    }
    //添加任务进度
    function showtasks(id) {
    		swal({ 
    			title: "是否完成？", 
    			type: "warning", 
    			showCancelButton: true, 
    			confirmButtonColor: "#DD6B55", 
    			confirmButtonText: "否", 
    			cancelButtonText: "是", 
    			closeOnConfirm: false, 
    			closeOnCancel: false 
    			}, 
    			function(isConfirm) { 
    				if (isConfirm) { 
    					swal({
       		    			title:"即将进入下一环节",
       		    			text: "1秒后自动关闭。", 
       		    			timer: 1000, 
       					    showConfirmButton: false
       		    		});
    					openyem("添加未完成原因", "<%=contextPath%>/taskCompletion/addView?taskId=" + id+"&status=3", 550, 300);
    					} else{ 
    						swal({
           		    			title:"即将进入下一环节",
           		    			text: "1秒后自动关闭。", 
           		    			timer: 1000, 
           					    showConfirmButton: false
           		    		});
    						openyem("添加完成情况", "<%=contextPath%>/taskCompletion/addView?taskId=" + id+"&status=2", 550, 600);
    						
    					} 
    				});
    }
  //添加任务进度
    function checktasks(id) {
    		swal({ 
    			title: "检查是否完成？", 
    			type: "warning", 
    			showCancelButton: true, 
    			confirmButtonColor: "#DD6B55", 
    			confirmButtonText: "否", 
    			cancelButtonText: "是", 
    			closeOnConfirm: false, 
    			closeOnCancel: false 
    			}, 
    			function(isConfirm) { 
    				if (isConfirm) { 
    					swal({
       		    			title:"即将进入下一环节",
       		    			text: "1秒后自动关闭。", 
       		    			timer: 1000, 
       					    showConfirmButton: false
       		    		});
    					openyem("添加返工原因", "<%=contextPath%>/taskCompletion/addView?taskId=" + id+"&status=4", 750, 700);
    					} else{ 
    						swal({
           		    			title:"即将进入下一环节",
           		    			text: "1秒后自动关闭。", 
           		    			timer: 1000, 
           					    showConfirmButton: false
           		    		});
    						openyem("添加完成情况", "<%=contextPath%>/taskCompletion/addView?taskId=" + id+"&status=5", 750, 700);
    						
    					} 
    				});
    }
    function openStatus(id){
    	openyem("查看完成情况", "<%=contextPath%>/taskCompletion/getCompletion?taskId=" + id, 550, 500);
    }
</script>
</body>
</html>

